package com.maket.scxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.feign.GetCodeFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.MesBom;
import com.maket.scxx.service.IMesBomService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产BOMController
 * 
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/bom")
public class MesBomController extends BaseController
{
    @Autowired
    private IMesBomService mesBomService;

    /**
     * 查询生产BOM列表
     */
    @RequiresPermissions("scxx:bom:list")
    @GetMapping("/list")
    public TableDataInfo list(MesBom mesBom)
    {
        startPage();
        List<MesBom> list = mesBomService.selectMesBomList(mesBom);
        return getDataTable(list);
    }

    /**
     * 导出生产BOM列表
     */
    @RequiresPermissions("scxx:bom:export")
    @Log(title = "生产BOM", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBom mesBom)
    {
        List<MesBom> list = mesBomService.selectMesBomList(mesBom);
        ExcelUtil<MesBom> util = new ExcelUtil<MesBom>(MesBom.class);
        util.exportExcel(response, list, "生产BOM数据");
    }

    /**
     * 获取生产BOM详细信息
     */
    @RequiresPermissions("scxx:bom:query")
    @GetMapping(value = "/{bomCode}")
    public AjaxResult getInfo(@PathVariable("bomCode") String bomCode)
    {
        return success(mesBomService.selectMesBomByBomCode(bomCode));
    }

    /**
     * 新增生产BOM
     */
    @Autowired
    private GetCodeFeign getCodeFeign;
    @RequiresPermissions("scxx:bom:add")
    @Log(title = "生产BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBom mesBom)
    {
        String code = getCodeFeign.getUser(21);
        mesBom.setBomCode(code);
        return toAjax(mesBomService.insertMesBom(mesBom));
    }

    /**
     * 修改生产BOM
     */
    @RequiresPermissions("scxx:bom:edit")
    @Log(title = "生产BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBom mesBom)
    {
        return toAjax(mesBomService.updateMesBom(mesBom));
    }

    /**
     * 删除生产BOM
     */
    @RequiresPermissions("scxx:bom:remove")
    @Log(title = "生产BOM", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bomCodes}")
    public AjaxResult remove(@PathVariable String[] bomCodes)
    {
        return toAjax(mesBomService.deleteMesBomByBomCodes(bomCodes));
    }
}
